package com.lxd.property.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lxd.property.pojo.Invoiceunit;
import com.lxd.property.service.InvoiceunitService;
import com.lxd.property.utils.Page;

@Controller
@RequestMapping("invoiceunit")
public class InvoiceunitController {

	@Autowired
	private InvoiceunitService invoiceunitService;

	@RequestMapping(value = "findAllInvoiceunit", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> findAllInvoiceunit(Page util,
			@RequestParam(value = "s_name", required = false) String s_name,Integer isqi) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("start", util.getStart());
		map.put("rows", util.getRows());
		map.put("s_name", s_name);
		map.put("isqi",isqi);
		List<Invoiceunit> list = invoiceunitService.findAllInvoiceunit(map);
		Long total = invoiceunitService.findAllInvoiceunitCount(map);
		Map<String, Object> con = new HashMap<String, Object>();
		con.put("total", total);
		con.put("rows", list);
		return con;
	}

	@RequestMapping(value = "findInvoiceunitById", method = RequestMethod.POST)
	@ResponseBody
	public Invoiceunit findInvoiceunitById(Integer id) {
		return invoiceunitService.findInvoiceunitById(id);

	}

	@RequestMapping(value = "judgeRepeation", method = RequestMethod.POST)
	@ResponseBody
	public Boolean judgeRepeation(Invoiceunit invoiceunit) {
		if (invoiceunit.getId() == null || invoiceunit.getId().equals("")) {
			return invoiceunitService.judgeRepeation(invoiceunit) == null;
		} else {
			return (invoiceunitService.judgeRepeation(invoiceunit) == null
					|| invoiceunit.getId().equals(invoiceunitService.judgeRepeation(invoiceunit).getId()));
		}
	}

	@RequestMapping(value = "updateInvoiceunit", method = RequestMethod.POST)
	@ResponseBody
	public Boolean updateInvoiceunit(Invoiceunit invoiceunit) {
		return invoiceunitService.updateInvoiceunit(invoiceunit) == 1;

	}

	@RequestMapping(value = "addInvoiceunit", method = RequestMethod.POST)
	@ResponseBody
	public Boolean addInvoiceunit(Invoiceunit invoiceunit) {
		return invoiceunitService.addInvoiceunit(invoiceunit) == 1;

	}

	@RequestMapping(value = "disableInvoiceunit", method = RequestMethod.POST)
	@ResponseBody
	public Boolean disableInvoiceunit(@RequestParam(value = "id", required = false) Integer id,
			@RequestParam(value = "states", required = false) Integer states) {
		Map<String,Object>map=new HashMap<String, Object>();
		states=states==0?1:0;
		map.put("id", id);
		map.put("states", states);
		return invoiceunitService.disableInvoiceunit(map) == 1;

	}
}
